#include<bits/stdc++.h>
using namespace std;

vector<int> days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};


vector<string> split(string s, char ch) {
    vector<string> ans;

    string t = "";
    for(auto ss : s) {
        if(ss == ch) {
            ans.push_back(t);
            t = "";
        } else {
            t += ss;
        }
    }
    ans.push_back(t);
    return ans;
}


vector<int> ss, ms, hs, ds, Ms;

void getSecond(string s) {

    if(s.find(',') != string::npos) {

        vector<string> t = split(s, ',');
        for(auto ii : t) ss.push_back(stoi(ii));

    } else if(s.find('-') != string::npos) {

        vector<string> t = split(s, '-');
        for(int i = stoi(t[0]); i <= stoi(t[1]); i++) ss.push_back(i);

    } else if(s.find('*') != string::npos) {

        for(int i = 0; i < 60; i++) ss.push_back(i);

    } else {
        ss.push_back(stoi(s));
    }
}


void getMinute(string s) {

    if(s.find(',') != string::npos) {

        vector<string> t = split(s, ',');
        for(auto ii : t) ms.push_back(stoi(ii));

    } else if(s.find('-') != string::npos) {

        vector<string> t = split(s, '-');
        for(int i = stoi(t[0]); i <= stoi(t[1]); i++) ms.push_back(i);

    } else if(s.find('*') != string::npos) {

        for(int i = 0; i < 60; i++) ms.push_back(i);

    } else {
        ms.push_back(stoi(s));
    }
}


void getHour(string s) {

    if(s.find(',') != string::npos) {

        vector<string> t = split(s, ',');
        for(auto ii : t) hs.push_back(stoi(ii));

    } else if(s.find('-') != string::npos) {

        vector<string> t = split(s, '-');
        for(int i = stoi(t[0]); i <= stoi(t[1]); i++) hs.push_back(i);

    } else if(s.find('*') != string::npos) {

        for(int i = 0; i < 24; i++) hs.push_back(i);

    } else {
        hs.push_back(stoi(s));
    }
}


void getDay(string s) {

    if(s.find(',') != string::npos) {

        vector<string> t = split(s, ',');
        for(auto ii : t) ds.push_back(stoi(ii));

    } else if(s.find('-') != string::npos) {

        vector<string> t = split(s, '-');
        for(int i = stoi(t[0]); i <= stoi(t[1]); i++) ds.push_back(i);

    } else if(s.find('*') != string::npos) {

        for(int i = 1; i < 32; i++) ds.push_back(i);

    } else {
        ds.push_back(stoi(s));
    }
}


void getMonth(string s) {

    if(s.find(',') != string::npos) {

        vector<string> t = split(s, ',');
        for(auto ii : t) Ms.push_back(stoi(ii));

    } else if(s.find('-') != string::npos) {

        vector<string> t = split(s, '-');
        for(int i = stoi(t[0]); i <= stoi(t[1]); i++) Ms.push_back(i);

    } else if(s.find('*') != string::npos) {

        vector<string> t = split(s, '*');
        for(int i = 1; i < 13; i++) Ms.push_back(i);

    } else {
        Ms.push_back(stoi(s));
    }
}


long long computeRes() {
    long long res = 0;

    for(auto month : Ms) {
        for(auto day : ds) {
            if(day > days[month]) break;

            res += 1ll * hs.size() * ms.size() * ss.size();
        }
    }
    return res;
}


signed main() {
//	system("start https://www.lanqiao.cn/problems/17115/learning/");

    string s;

    for(int i = 0; i < 5; i++) {
        cin >> s;
        switch(i) {
            case 0:
                getSecond(s);
                break;
            case 1:
                getMinute(s);
                break;
            case 2:
                getHour(s);
                break;
            case 3:
                getDay(s);
                break;
            case 4:
                getMonth(s);
                break;
        }
    }

    cout << computeRes();

    return 0;
}

